var obUser


////////
window.onresize = function () {
    var W = document.documentElement.clientWidth;
    var H = document.documentElement.clientHeight;
    //调整布局大小
    if (W > 1100 && H > 670) {
        document.getElementById("divWrapper").setAttribute("style", "width: " + document.documentElement.clientWidth + "px;height:" + document.documentElement.clientHeight + "px;")
    } else {
        if (W > 1000) {
            document.getElementById("divWrapper").setAttribute("style", "width: " + W + "px")
        }
        if (H > 670) {
            document.getElementById("divWrapper").setAttribute("style", "height:" + H + "px;")
        }
    }
    //调整布局大小
    // if(document.documentElement.clientWidth>0&&document.documentElement.clientHeight>0){
    //
    // }
}


/////////


$(document).ready(function () {
    //登录
    if (document.documentElement.clientWidth > 0 && document.documentElement.clientHeight > 0) {
        document.getElementById("divWrapper").setAttribute("style", "width: " + document.documentElement.clientWidth + "px;height:" + document.documentElement.clientHeight + "px;")
    }

    $("#loginButton").click(function () {
        var id = $("#loginid").val();
        var paw = $("#loginpaw").val();
        if (id == null || id == undefined || id == "") {
            alert("账号不可为空！");
            return;
        }
        if (paw == null || paw == undefined || paw == "") {
            alert("密码不可为空！");
            return;
        }
        $.post("login", {
                id: id,
                paw: paw,
                permission:'0'
            },
            function (data, status) {
                // alert(typeof  JSON.parse(data))
                obUser = JSON.parse(data);

                alert("状态: " + obUser.meg);
                if (obUser.meg == "登录成功") {
                    window.location.reload();
                }

            });
    });

    function lbutton(member) {
        if (member == "" || member == null || member == undefined) {
            return;
        } else {
            // $("#loginid").val("");
            // $("#loginpaw").val("");
            $("#alogin").text("注销");
            // $(".divlogin").css({display: "none"});
        }
    }

//注册
    $("#registerButton").click(function () {
        var id = $("#reid").val();
        var pwa1 = $("#repaw1").val();
        var pwa2 = $("#repaw2").val();
        var name = $("#rename").val();
        if (id == null || id == undefined || id == "") {
            alert("账号不可为空！");
            return;
        }
        if (name == null || name == undefined || name == "") {
            alert("姓名不可为空！");
            return;
        }

        if (pwa1 == null || pwa1 == undefined || pwa1 == "") {
            alert("密码不可为空！");
            return;
        }
        if (pwa2 == null || pwa2 == undefined || pwa2 == "") {
            alert("密码不可为空！");
            return;
        }
        if (pwa1 != pwa2) {
            alert("两次密码不相同！");
            return;
        }
        $.post("register", {
                id: id,
                paw: pwa1,
                name: name,
                permission: '0'
            },
            function (data, status) {
                var ob = JSON.parse(data);
                alert(ob.meg);


            });
    });


});

function todivLogin() {
    if ($("#alogin").text() == "注销") {
        alert("注销成功");
        {//注销功能待实现

        }
        $("#alogin").text("登录")
    }
    $(".divlogin").css({display: "block"});

}

function closeCreateClazz() {
    $(".createClazz").css({display: "none"});

}

function closeInsertClazz() {
    $(".insertClazz").css({display: "none"});

}

function closeLoginView() {
    $(".divlogin").css({display: "none"});
}

function toInputLogin() {
    $("#log").css({display: "block"});
    $("#reg").css({display: "none"});
}

function toInputRegister() {
    $("#log").css({display: "none"});
    $("#reg").css({display: "block"});
}


$(".insertClazz>input, .createClazz>input").click(function () {
    $(".createClazz").css({display: "none"});
    $(".insertClazz").css({display: "none"});

});

function cerateClass(member) {

    if (member == "" || member == null || member == undefined) {
        alert("请先登录")
        $(".divlogin").css({display: "block"});
        return;
    }


    $(".createClazz").css({display: "block"});
    $(".insertClazz").css({display: "none"});
}

function insertClass(member) {

    if (member == "" || member == null || member == undefined) {
        alert("请先登录")
        $(".divlogin").css({display: "block"});
        return;
    }
    $(".insertClazz").css({display: "block"});
    $(".createClazz").css({display: "none"});
}

function toMain() {
    $("#changeView").attr("src", "main");

}

function toMyClazz(member) {
    if (member == "" || member == null || member == undefined) {
        alert("请先登录")
        $(".divlogin").css({display: "block"});
        return;
    }
    $("#changeView").attr("src", "myclazz.jsp");

}

